pp108 : ondrag Property

ondrag Property


This is an optional property; it contains the pointer to a function to be called when an item in the tree is dragged.

Syntax

XML

<TreeItem>
    <searchPath>sName</searchPath>
    <description>sDesc</description>
    <dragEnabled>bDrag</dragEnabled>
    <ondrag>fpFunction</ondrag>
        ...
        ...
        ...
</TreeItem>


Parameters

Parameter

Description

fpFunction

Pointer to a function that is to be called when an item in the tree is dragged.


Remarks


After dragging is enabled on a tree item, the item can be dragged and dropped from one tree node to another node. To enable dragging, set the dragEnabled property to true.
To drag an item, select the item and hold the mouse on the item, and move the pointer to another tree node. Once the other node is reached, release the mouse click. However, dragging the node will not update the corresponding data in the tree. It is the responsibility of the users to manually change the treeData.

To prevent the dragging functionality on an item, you must use the cordys.preventDefault(eventObject) function.

Example


The following example shows how the property is used.

<!-- Schema for tree. "dragHandler" is a function that will be called when item is dragged -->
<script type="cordys/xml" id="schema">
    <TreeSchema>
        <searchPath>//data/tuple/old/</searchPath>
        <Root>
            <description>Employees</description>
        </Root>
        <TreeItem id="EmployeesID">
            <searchPath>Employees</searchPath>
            <description>FirstName</description>
            <dragEnabled>true</dragEnabled>
            <ondrag>dragHandler</ondrag>
        </TreeItem>
    </TreeSchema>
</script>
//Function call
function dragHandler(draggedNode, eventObject)
{
    <!-- Alert data of the dragged item -->
    application.notify("item dragged : " + cordys.getXML(draggedNode.data));
    <!-- Return without dragging  -->
    cordys.preventDefault(eventObject);
}

See Also


tree